package com.huadao.cart_ccs.experiment.afterCulture;

import com.huadao.cart_ccs.data.bo.CommandWord;
import com.huadao.cart_ccs.data.bo.DoorBO;
import com.huadao.cart_ccs.data.bo.UltravioletLightBO;
import com.huadao.cart_ccs.modle.DoorModle;
import com.huadao.cart_ccs.modle.UltravioletLightModle;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class AfterCulturePresenter extends IAfterCultureContract.IAfterCulturePresenter {

    private DoorModle doorModle;

    public AfterCulturePresenter(IAfterCultureContract.IAfterCultureView baseView) {
        attachView(baseView);
        doorModle=new DoorModle();
        EventBus.getDefault().register(this);
    }

    @Override
    void openDoor() {
        doorModle.open();
    }

    @Override
    void closeDoor() {
        doorModle.close();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(DoorBO event) {
        byte commondWord = event.getCommondWord();
        if(commondWord == CommandWord.writeSucc[0]){
            if(event.getOrder()==DoorBO.open){
                baseView.onDoorOpen();
            }else if(event.getOrder()==DoorBO.close){
                baseView.onDoorClose();
            }
        }else if(commondWord == CommandWord.readFail[0]){
            baseView.showToast(event.toString());
        }
    }
}
